package com.nb.fly.controller;

import com.nb.fly.request.QueryShopRequest;
import com.nb.fly.request.SaveShopRequest;
import com.nb.fly.request.UpdateShopRequest;
import com.nb.fly.response.ResponseVO;
import com.nb.fly.response.ShopListVO;
import com.nb.fly.response.ShopVO;
import com.nb.fly.service.ShopService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * ${NMAE}
 *
 * @author Gwg
 * @date 2020/6/28
 **/
@Api(tags = "shop", description = "shop")
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @PostMapping
    public ResponseVO create(@RequestBody @Valid SaveShopRequest request) throws Exception{
        shopService.create(request);
        return new ResponseVO();
    }

    @GetMapping
    public ResponseVO<ShopListVO> search(@Validated QueryShopRequest request) throws Exception {
        return new ResponseVO<ShopListVO>().success(shopService.queryShop(request));
    }

    @PutMapping
    public  ResponseVO update(@RequestBody @Valid UpdateShopRequest request) throws  Exception{
        shopService.update(request);
        return new ResponseVO();
    }
}
